﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Tasks;

namespace PriceCuttingWar
{
	public partial class UIStartGameInterface : UserControl
	{
        public UIStartGameInterface()
        {
            // 为初始化变量所必需
            InitializeComponent();
            ANI_Start.Completed += new EventHandler(ANI_Start_Completed);
            Btn_MoneyMode.Tag = EmGameMode.Money;
            Btn_CutMode.Tag = EmGameMode.Cutting;
            Btn_AndMode.Tag = EmGameMode.And;
            Btn_MoneyMode.Click += new RoutedEventHandler(Btn_MoneyMode_Click);
            //Btn_MoneyMode.MouseEnter += new MouseEventHandler(Btn_Mode_MouseEnter);
            //Btn_MoneyMode.MouseLeave += new MouseEventHandler(Btn_Mode_MouseLeave);
            Btn_CutMode.Click += new RoutedEventHandler(Btn_CutMode_Click);
            //Btn_CutMode.MouseEnter += new MouseEventHandler(Btn_Mode_MouseEnter);
            //Btn_CutMode.MouseLeave += new MouseEventHandler(Btn_Mode_MouseLeave);
            Btn_AndMode.Click += new RoutedEventHandler(Btn_AndMode_Click);
            //Btn_AndMode.MouseEnter += new MouseEventHandler(Btn_Mode_MouseEnter);
            //Btn_AndMode.MouseLeave += new MouseEventHandler(Btn_Mode_MouseLeave);
            Btn_HighestScore.Click += new RoutedEventHandler(Btn_HighestScore_Click);
            Btn_Howtoplay.Click += new RoutedEventHandler(Btn_Howtoplay_Click);
            Btn_PlayNow.Click += new RoutedEventHandler(Btn_PlayNow_Click);
            foreach (var item in BackFoods.Children)
            {
                (item as UIFood).Type = GSystem.GamesRandom.Next() % 6;
            }
            UICard_Mony.Money2.Text = "61";
            UICard_Mony2.Money2.Text = "61";
            UICard_Cut.Money2.Text = "70%";
            UICard_Cut2.Money2.Text = "70%";
            this.CacheMode = new BitmapCache();
            if(GamePlayCount.IsTrialMode)
            {
                Btn_BuyFull.Visibility = System.Windows.Visibility.Visible;
                Btn_BuyFull.Click += new RoutedEventHandler(Btn_BuyFull_Click);
            }
            else
                Btn_BuyFull.Visibility = System.Windows.Visibility.Collapsed;
        }

        void Btn_BuyFull_Click(object sender, RoutedEventArgs e)
        {
            MarketplaceDetailTask place = new MarketplaceDetailTask();
            //place.ContentType = MarketplaceContentType.Applications;
            //place.ContentIdentifier = GSystem.GUID;
            place.Show();
        }

        void Btn_PlayNow_Click(object sender, RoutedEventArgs e)
        {
            MainPage.isStartShow = false;
            if (GamePlayCount.IsTrialMode)
            {
                if (GamePlayCount.Remainder <= 0)
                {
                    if (MessageBox.Show(
                         "No remaining times,Buy fullversion or re-install,Are you buy now ?",
                         "No remaining times",
                         MessageBoxButton.OKCancel
                         ) == MessageBoxResult.OK)
                    {
                        MarketplaceDetailTask place = new MarketplaceDetailTask();
                        //place.ContentType = MarketplaceContentType.Applications;
                        place.ContentIdentifier = GSystem.GUID;
                        place.Show();
                    }
                }
                else
                    GSystem.HowToPlay.Show();
            }
            GSystem.HowToPlay.Show();
            StartGameInterface.Visibility = System.Windows.Visibility.Collapsed;
            SelectModeInterface.Visibility = System.Windows.Visibility.Visible;
        }
        public void Rest()
        {
            StartGameInterface.Visibility = System.Windows.Visibility.Visible;
            SelectModeInterface.Visibility = System.Windows.Visibility.Collapsed;
            HowToPlayInterface.Visibility = System.Windows.Visibility.Collapsed;
            HighestScoreInterface.Visibility = System.Windows.Visibility.Collapsed;
        }
        
        void Btn_Howtoplay_Click(object sender, RoutedEventArgs e)
        {
            MainPage.isStartShow = false;
            GSystem.HowToPlay.ShowMe();
        }

        void Btn_HighestScore_Click(object sender, RoutedEventArgs e)
        {
            MainPage.isStartShow = false;
            GSystem.HighestScore.Show();
        }

        void Btn_Mode_MouseLeave(object sender, MouseEventArgs e)
        {
            //foreach (var item in TipBoxGroup.Children)
            //{
            //    item.Visibility = Visibility.Collapsed;
            //}
        }

        void Btn_Mode_MouseEnter(object sender, MouseEventArgs e)
        {
            //foreach (var item in TipBoxGroup.Children)
            //{
            //    item.Visibility = Visibility.Collapsed;
            //}
            switch ((EmGameMode)(sender as Button).Tag)
            {
                case EmGameMode.Money:
                    TipBox1.Visibility = Visibility.Visible;
                    break;
                case EmGameMode.Cutting:
                    TipBox2.Visibility = Visibility.Visible;
                    break;
                case EmGameMode.And:
                    TipBox3.Visibility = Visibility.Visible;
                    break;
            }

        }

        void Btn_AndMode_Click(object sender, RoutedEventArgs e)
        {
            ANI_Start.Begin();
            GSystem.GameMode = EmGameMode.And;
            //foreach (var item in TipBoxGroup.Children)
            //{
            //    item.Visibility = Visibility.Collapsed;
            //}
        }

        void Btn_CutMode_Click(object sender, RoutedEventArgs e)
        {
            ANI_Start.Begin();
            GSystem.GameMode = EmGameMode.Cutting;
            //foreach (var item in TipBoxGroup.Children)
            //{
            //    item.Visibility = Visibility.Collapsed;
            //}
        }

        void Btn_MoneyMode_Click(object sender, RoutedEventArgs e)
        {
            ANI_Start.Begin();
            GSystem.GameMode = EmGameMode.Money;
            //foreach (var item in TipBoxGroup.Children)
            //{
            //    item.Visibility = Visibility.Collapsed;
            //}
        }

        void ANI_Start_Completed(object sender, EventArgs e)
        {
            GSystem.Root.StartGame();
        }
	}
}